let mysql = require('mysql')
let conn = mysql.createConnection({
    host: '127.0.0.1',
    port: 3306,
    user: 'root',
    password: '123456',
    database: 'en'
})

// 测试连接
// conn.connect(err=>{
//     if(err) console.log(err)
//     else console.log('mysql连接成功')
// })

module.exports = function(obj = {}){
    let { sql, value = false, next } = obj
    return new Promise((resolve, reject)=>{
        conn.query(sql, value, (err, data)=>{
            if(err){
                next ? next(err) : reject(err)
            }else{
                resolve(data)
            }
        })
    })
}